tibasicfandomcom-20200215-history
TI-Basic Nspire Programming
Introduction Some of you may have noticed after you upgraded to the TI-Nspire that the programming is a little bit different and maybe a little bit confusing even for experienced programmers. Hopefully this guide will help. Please note that I myself am new to the Nspire and as a result my thoroughness on its programming is extremely limited, but I will update this page as I learn more. Types of Variables As with the TI-89, the Nspire has two main kinds of variables: global and local. A global variable is the most common variable. It maintains its value throughout the document. It will have a different value in a different document. When you use a global variable, it will show up in the Var list. A local variable only maintains its value inside of the program or function that it is used. After the program or function has ended, the variable loses its value. Both kinds of variables can be used the same exact way; however, before a local variable can be used, it must be declared. All this consists of is typing at the beginning of the program "Local var1,var2...". This defines the variable as being local to the program or function. Any variables that are not declared this way will be considered global. Inputting Variables Many of you may have noticed the lack of the normal Input or Prompt commands. Instead, you have 2 choices of inputting variables: Request or argument. Request The request function works much the same way as on the TI-89. It has the same syntax as on the 89 except the optional portion is different. Request with flags.gif|Programming example using request with flags. Request without flags.gif|Programming example using request without flags. Define Example()= Prgm request string,var,dispflag EndPrgm The string is what you want the window to ask for. Var is the variable to store the value in. The optional display flag controls whether or not it will show the value on the next line. By default this value is 1. If you change it to 0 no value will be returned. Arguments The other option for inputting variables is to use arguments. Arguments are what are entered into the parenthesis and may or may not be seperated by commas. The syntax takes a little getting used to but it is simple. Define Example(var1,var2...) Prgm EndPrgm When you set up the program to use arguments, those arguments must be entered at the execution of the program. Outputting As with the input commands, the Nspire has lost a few of the output commands. The Nspire has lost output, Pt-text,and Pxl-text. All that remains is Disp, Return, and Text. Disp Disp operates almost the same way as on other calculators. Unlike other calculators, the Nspire will wrap the text here. The syntax is the same, however, when bits of it are separated by commas the actual output is separated by a space instead of a line as with the 83s, 84s and 89s. To separate by a line, you can simply press enter within a string, or use another disp command. This can be seen in the picture used as the argument example. Return Return operates the same exact way as on other calculators. It maintains the same syntax as well as usability. The return command can only be used in a function and can only be used to output one value. You cannot use more than one return to achieve the same effect either. Anything other than the first return will be ignored by the calculator. Text The text command is very similar to both request and disp. While request asks for an input in a pop up window and disp simply displays information, Text displays information in a pop up window. The only drawback of Text is that you cannot use it to display the value of a variable. It can only display a string. Libraries and Documents As you may have noticed, the Nspire can separate different types of problems or different information into documents. As I stated earlier variables are only maintained within the document in which they are created. The Nspire recognizes programs and functions as variables and therefore can only be used in the document in which they were created. If this document gets deleted for some reason, so do all of its variables, including all programs and functions. This is where libraries come in. Creating Libraries Libraries are documents that can be accessed from any document. Simply put, any program or function written into a library can be accessed from any document. To create a library, you must first save the document into the MyLib folder. If this folder is missing, just make a new folder in My Documents and title it MyLib. Now, once document is saved, library objects must be defined within the first problem of the document (the problem number is the first number of each tab at the top left. i.e. 1.5.). To define a program or a function as a library object, when you first create the program or function, under Library Access, select either LibPriv or LibPub. The only difference is that under LibPub, the program or function will show up under the fifth tab of the catalog. Then you can write the program or function as normal. If you accidently skipped the library access you can change it by going to "menu">>"Actions">>"Library">>"Change Library Access". Store the program or function (ctrl+b) then save the document. Open up any other document and goto "Menu">>"Actions">>"Library">>"Refresh Libraries" then type libshortcut("libraryname","yourshortcut"). Now your programs should show up in the var list as "yourshortcut.yourprogram". Each time you add a program or function, you must refresh libraries for the change to take effect. menu1.gif|Press the Menu button menu2.gif|Click Action menu3.gif|Click Library then click Refresh Libraries Another Way to Access a Library There is an alternate way to access a library. This way is, in my opinion, more tedious, because it must be done for each program in the library individually whereas the first method will allow access to all current and future programs just by refreshing the library. Now, to access the library, follow the steps above except, instead of typing libshortcut(), goto "Menu">>"Programs and Functions">>"Program Editor">>"Import...". Under "Library Name" select your library name, then, under "Name" select the program or function to import, and finally under 'Import as:" type what you want as the name of the imported program. Like I said before, this process must be repeated for every program that you want to import. Comments Comments are just what you think. You can place a comment in a program or function and it will have absolutely no effect on the running of the program. The only time you will see a comment outside of the program is if the program is in a library and is defined as LibPub. A program defined this way will show up under the fifth tab of the catalog. If the program has a comment, about 40 characters of the first comment will be shown in the description. To add a comment, press "Menu">>"Actions">>"Insert Comment". That will place a © symbol on the line. Type your comment after that. Anything placed on the same line will be considered a comment. Please keep in mind that the Nspire sometimes wraps the text entered. A good rule of thumb is if the text is it italics, the calculator has not recognized it as anything and will probably return an error. Neither comments nor commands will be shown in italics. Category:TI-Basic Nspire Programming Category:Reference